﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ShopOnline.Models.DAL
{
    public class DAL_SentMail
    {
        private ShopOnline.Models.ShopOnlineDBDataContext SC_DB;
        public DAL_SentMail()
        {
            SC_DB = new ShopOnlineDBDataContext();
        }


        public List<SentMail> getListSentMail()
        {
            return SC_DB.SentMails.ToList();
        }


        public SentMail getSentMaileById(int sentMail)
        {
            return (from c in SC_DB.SentMails where c.sendmailId == sentMail select c).FirstOrDefault();
        }

        public int CreateSentMail(SentMail sentMail)
        {
            int result = 0;
            try
            {
                SC_DB.SentMails.InsertOnSubmit(sentMail);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }

        public int EditSentMail(SentMail sen)
        {
            int result = 0;
            try
            {
                var senmail = (from c in SC_DB.SentMails where c.sendmailId == sen.sendmailId select c).FirstOrDefault();
                senmail.address = sen.address;
                senmail.body = sen.body;
                senmail.dateSent = senmail.dateSent;
                senmail.email = senmail.email;
                senmail.name = senmail.name;
                senmail.phone = senmail.phone;
                senmail.show = senmail.show;
                senmail.title = senmail.title;
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
        public int DeleteSentMail(SentMail sen)
        {
            int result = 0;
            try
            {
                var pic = (from c in SC_DB.SentMails where c.sendmailId == sen.sendmailId select c).FirstOrDefault();
                SC_DB.SentMails.DeleteOnSubmit(sen);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
    }
}